package restPROC;




import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;


import dao.daoKonekcija;
import dao.daoKorisnik;



@Path("/login") 
public class LogIn {

	
	@POST
	@Path("/provjera")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces("text/plain")
	public String jelIsti(@FormParam("user") String uid, @FormParam("pass") String pass,@Context HttpServletRequest req)
	{
		String rez=(new Boolean(false)).toString();
		try {
			
			rez=daoKorisnik.ProvjeriHash(uid, pass).toString();
			HttpSession sess = req.getSession(true);
			if(sess.getAttribute("korisnik")==null){
				sess.setAttribute("korisnik", uid);
			}
			System.out.print(uid+" "+pass);
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return rez;
	}
	
	@GET
	@Path("/obrisisession")
	public String logout(@Context HttpServletRequest req){
		HttpSession sess = req.getSession();
		sess.setAttribute("korisnik", null);
		sess.invalidate();
		return "true";
	}

}
